/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include "sle_ssap_client_interface.h"
#include "kh_sle_ssap_client.h"
#include "cmd_input.h"
#include <vector>
#include <memory>
#include <cstring>
#include <iterator>

namespace OHOS {
namespace NearLink {
namespace SleStandard {
namespace {
using namespace testing::ext;
} // namespace

class SsapcHandlerTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp();
    void TearDown();
};

uint8_t g_clientId;

void SsapcHandlerTest::SetUpTestCase() {}

void SsapcHandlerTest::TearDownTestCase() {}

void SsapcHandlerTest::SetUp() {
    SleErrorCode ret = InitSleSsapcService();
    printf("ret = %d", ret);
}

void SsapcHandlerTest::TearDown() {}

HWTEST_F(SsapcHandlerTest, AddSspaClientTest, TestSize.Level1)
{
    SleUuid appUuid;
    appUuid.len = 1;
    appUuid.uuid[0] = 1;
    uint8_t clientId = 255;
    SleErrorCode ret = AddSspaClient(&appUuid, &clientId);
    EXPECT_EQ(ret, SLE_NO_ERROR);
}

HWTEST_F(SsapcHandlerTest, RemoveClientTest, TestSize.Level1)
{
    uint16_t clientId = 255;
    SleErrorCode ret = RemoveClient(clientId);
    EXPECT_EQ(ret, SLE_ERR_INVALID_PARAM);
}

HWTEST_F(SsapcHandlerTest, FindSsapStructureTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    ClientFindStructure paramFind;
    paramFind.findType = (SsapFindType )1;
    paramFind.startHandle = (uint16_t)1;
    paramFind.endHandle = (uint16_t)1;
    SleErrorCode ret = FindSsapStructure(g_clientId, connectId, &paramFind);
    EXPECT_EQ(ret, SLE_ERR_INTERNAL_WRONG);
}

HWTEST_F(SsapcHandlerTest, SendReadReqByUuidTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    ClientReadReqByUUID paramRead;
    paramRead.findType = (SsapFindType)1;
    paramRead.startHandle = (uint16_t)1;
    paramRead.endHandle = (uint16_t)1;
    // SleGetInputString("please input uuid: ", (char*)paramRead.uuid.uuid, UUID_LEN);
    paramRead.uuid.len = UUID_LEN;
    paramRead.uuid.uuid[0] = 0;
    SleErrorCode ret = SendReadReqByUuid(g_clientId, connectId, &paramRead);
    EXPECT_EQ(ret, SLE_ERR_INTERNAL_WRONG);
}

HWTEST_F(SsapcHandlerTest, SendReadReqTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    uint16_t handle = 255;
    SleSsapPropertyType propertyTpye = (SleSsapPropertyType )1;
    SleErrorCode ret = SendReadReq(g_clientId, connectId, handle, propertyTpye);

    EXPECT_EQ(ret, SLE_ERR_INTERNAL_WRONG);
}

HWTEST_F(SsapcHandlerTest, SendWriteReqTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    ClientWriteParam paramWrite;
    paramWrite.handle = (uint16_t)0;
    paramWrite.type = (SleSsapPropertyType)0;
    uint8_t data[256];
    const char* str = "nearlink test";
    strncpy(reinterpret_cast<char*>(data), str, sizeof(data));
    paramWrite.dataLength = strlen((char*)data) + 1;
    paramWrite.data = data;
    SleErrorCode ret = SendWriteReq(g_clientId, connectId, &paramWrite);
    EXPECT_EQ(ret, SLE_ERR_INTERNAL_WRONG);
}

HWTEST_F(SsapcHandlerTest, SendWriteCmdTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    ClientWriteParam paramWrite;
    paramWrite.handle = (uint16_t)10;
    paramWrite.type = (SleSsapPropertyType )1;
    int dataLen = 20;
    uint8_t *data = (uint8_t *)malloc(dataLen * sizeof(uint8_t));
    memset(data, 'C', dataLen);
    const char* str = "nearlink test";
    strncpy(reinterpret_cast<char*>(data), str, sizeof(data));
    paramWrite.dataLength = dataLen;
    paramWrite.data = data;
    SleErrorCode ret = SendWriteCmd(g_clientId, connectId, &paramWrite);
    EXPECT_EQ(ret, SLE_ERR_INTERNAL_WRONG);
}

HWTEST_F(SsapcHandlerTest, SendExchangeInfoReqTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    SsapMtuInfo paramExchange;
    paramExchange.mtuSize = 256;
    SleErrorCode ret = SendExchangeInfoReq(g_clientId, connectId, &paramExchange);
    EXPECT_EQ(ret, SLE_ERR_INTERNAL_WRONG);
}
}
} // namespace NetManagerStandard
} // namespace OHOS